package com.mouse.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mouse.entity.GeneComposition;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mouse.entity.Reference;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author godson
 * @since 2022-08-07
 */
public interface GeneCompositionMapper extends BaseMapper<GeneComposition> {


    @Select("SELECT gcom.* FROM gene_composition gcom where gcom.gene_allelename_composition=#{gac}")
    Page<GeneComposition> getGeneCompositionByGAC(Page<GeneComposition> page, @Param("gac") String gac);

    @Select("SELECT gcom.* FROM gene_category gca LEFT JOIN genecategory_genecomposition gg ON gca.gid=gg.gid LEFT JOIN gene_composition gcom ON gg.gcid=gcom.gcid WHERE gca.gid=#{gid}")
    List<GeneComposition> getGeneCompositionByGid(@Param("gid") Long gid);


    /***
     * 3.2.1.1
     * @param did
     * @return
     */
    @Select("SELECT gc.* FROM (SELECT gcda.gcid FROM  double_alleles da LEFT JOIN gene_composition_double_alleles gcda ON da.did=gcda.did WHERE da.did=#{did}) res LEFT JOIN gene_composition gc on res.gcid=gc.gcid")
    List<GeneComposition> getGeneCompositionByDid( @Param("did") Long did);

    /***
     * 4.2.2.1
     * @param aid
     * @return
     */
    @Select("SELECT DISTINCT gcom.* FROM gene_allele ga LEFT JOIN double_alleles_gene_allele daga ON ga.aid=daga.aid LEFT JOIN double_alleles da ON daga.did= da.did \n" +
            "LEFT JOIN gene_composition_double_alleles gcda ON gcda.did=da.did LEFT JOIN gene_composition gcom on gcda.gcid=gcom.gcid\n" +
            "WHERE daga.aid=#{aid}")
    List<GeneComposition> getGeneCompositionByAid(@Param("aid") Long aid);





}
